package main

import "fmt"

// 父类
type Animal struct {
	name string
	age  int
}

func (animal Animal) eat() {
	fmt.Println(animal.name, "eating...")
}
func (animal Animal) sleep() {
	fmt.Println(animal.name, "sleeping...")
}

// 子类 继承父类变量和方法
type Dog struct {
	Animal
	playing_cnt int
}

func (animal Dog) play() {
	fmt.Println(animal.name, "playing...")
}

// 子类 继承父类变量和方法
type Cat struct {
	Animal
	color string
}

// 子类方法重写
func (cat Cat) eat() {
	fmt.Println("Cat", cat.name, "eating...")
}

func (animal Cat) breathe() {
	fmt.Println(animal.name, "breathing...")
}

func main() {
	var xiaohuang Dog
	xiaohuang.name = "xiaohuang"
	xiaohuang.age = 20
	xiaohuang.playing_cnt = 10
	xiaohuang.eat()
	xiaohuang.sleep()
	xiaohuang.play()
	hajimi := Cat{
		Animal: Animal{
			name: "hajimi",
			age:  12,
		},
		color: "yellow",
	}
	jimiha := Cat{
		Animal: Animal{
			name: "jimiha",
			age:  12,
		},
		color: "white",
	}
	jimiha.eat()
	hajimi.Animal.eat() //重写后调用父类的
	hajimi.eat()        //调用子类自己的
	hajimi.sleep()
	hajimi.breathe()

}
